<template>
    <div class="goodsListContain">


        <div class="goodItem" v-for="(item,index) in goodsList" :key="index" @click="goGoodInfo(item.id)">
            <div class="goodShow">
                <img :src="item.img_url" alt="">
                <p class="goodTitle">{{item.title}}</p>
            </div>
            <div class="info">
                <div class="price">
                    <span class="newPrice">￥{{item.sell_price}}</span>
                    <span class="oldPrice">￥{{item.market_price}}</span>
                </div>
                <div class="count">
                    <span>热卖中</span>
                    <span class="goodCount">剩{{item.stock_quantity}}件</span>
                </div>
            </div>
        </div>

        <button type="button" class="mui-btn mui-btn-primary submitBtn" @click="addPageIndex">加载更多
        </button>
    </div>
</template>

<script>
    export default {
        data: function () {
            return {
                goodsList: [],
                id: 1
            }
        },
        methods: {
            getGoodsList() {
                this.$http.get('http://www.liulongbin.top:3005/api/getgoods?pageindex=' + this.id).then(data => {
                    this.goodsList = this.goodsList.concat(data.body.message);
                })
            },
            addPageIndex() {
                this.id++;
                this.getGoodsList();
            },
            goGoodInfo(id) {  //编程式导航，跳转页面
                this.$router.push('/home/goodsInfo/' + id);
            }
        },
        created() {
            this.getGoodsList();
        }
    }

</script>

<style scoped lang="less">
    .goodsListContain {
        padding: 6px;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;

        .goodItem {
            width: 49%;
            border: 1px solid #ccc;
            box-shadow: 0 0 5px #ccc;
            margin-bottom: 6px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;

            .goodShow {
                img {
                    width: 100%;
                }

                .goodTitle {
                    font-size: 14px;
                    font-weight: bold;
                    color: #333;
                }
            }

            .info {
                background-color: #dfe6e9;
                padding: 6px;

                .price {
                    margin-bottom: 5px;

                    span:first-child {
                        color: #d63031;
                        font-size: 16px;
                    }

                    span:last-child {
                        color: #8f8f94;
                        font-size: 13px;
                        text-decoration: line-through;
                        margin-left: 5px;
                    }
                }

                .count {
                    display: flex;
                    justify-content: space-between;
                    font-size: 13px;
                    color: #8f8f94;
                }
            }
        }

        .mui-btn {
            width: 100%;
        }
    }
</style>
